import { UrlService } from './../../../providers/url-service';
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Api } from '../../../providers/api-service';
import { NoticeService } from '../../../providers/notice-service';
import { UserDetialChallengePage } from '../../user/user-detial-challenge/user-detial-challenge';

/**
 * 挑战详情多人
 */

@Component({
  selector: 'page-challenge-detial-three-start',
  templateUrl: 'challenge-detial-three-start.html',
})
export class ChallengeDetialThreeStartPage {
  ChallengeDetialID;
  pageData = [];
  pageDataIsok = false;
  //打卡 动态
  userDTlist = [];
  //排行榜
  RankingList = [];
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public urlService: UrlService,
    public noticeService: NoticeService,
    public api: Api
  ) {
    this.ChallengeDetialID = navParams.get("ChallengeDetialID");
  }

  ionViewDidLoad() {
    console.log('挑战详情 多人 ChallengeDetialThreeStartPage');
    this.GetDekaronInfo(this.ChallengeDetialID);
    this.GetAllDekaronDynamicById(this.ChallengeDetialID);
    this.GetDekaronStatisticsById(this.ChallengeDetialID);
  }

  /**
   * 获取详情
   */
  GetDekaronInfo(ID) {
    // item.DekaronID ="6B11D20F-9C03-415F-92A5-9D2F22A6C339";
    this.urlService.GetDekaronInfo(ID)
      .then(msg => {
        if (msg.Code == 0) {
          this.pageDataIsok = true;
          this.pageData[0] = msg.Data;
          this.isJonbnt = this.isJon();
          this.userDTlist = msg.Data.joinlist

        }
      })
  }

  /**
   * 排行榜
   */
  GetDekaronStatisticsById(ID) {
    debugger
    this.api.postBody("V1/GetDekaronStatisticsById", { "PageIndex": 1, "PageSize": 20, id: ID })
      .then((data) => {
        if (data.Code == 0) {
          this.RankingList = data.Data;
        }
      })
  }

  /**
   *动态 
   */
  GetAllDekaronDynamicById(ID) {
    this.api.postBody("V1/GetAllDekaronDynamicById", { "PageIndex": 1, "PageSize": 20, ID: ID })
      .then((data) => {
        console.log(data);
        console.log("动态");
        if (data.Code == 0) {
          // this.userDTlist = data.Data.Items;
        }
      })
  }

	/**
   * 下拉刷新
   * @param refresher 
   */
  doRefresh(refresher) {
    this.ionViewDidLoad();
    setTimeout(() => {
      refresher.complete();
    }, 2000);
  }
  /**
   * 人员详情
   */
  tabUser(item) {
    this.navCtrl.push(UserDetialChallengePage, { "userID": item.ID });
  }
  /**
   * 头部左边按钮
   */
  navRingt() {



  }
  /**
   * 打开成员列表
   */
  openCR() {

  }

  /**
   * tab 页选择
   */
  act = [false, true, false];
  navSelected(ittem) {
    for (let index = 0; index < this.act.length; index++) {
      this.act[index] = false;
      if (index == ittem) {
        this.act[index] = true;
      }
    }
  }


  /**
   * 参加挑战
   */
  openTiaozhan() {
    this.noticeService.presentConfirm("提示", "参加挑战系统将扣除您" + this.pageData[0].Integral + "战豆，是否确定参加？", () => {
      this.api.postBody("V1/ApplyJoinDekaron", { DekaronID: this.ChallengeDetialID })
        .then((data) => {
          let str = "";
          if (data.Code == 0) {
            str = "已参加";
          } else {
            str = "您已参加过挑战，无需再次报名！";
          }
          if (str != "") {
            this.noticeService.showNoticeByToast(1, str);
          }
        })
    });
  }
  /**
   * 是否显示参加按钮
   */
  isJonbnt = false;
  /**
   * 判断是否参加了当前挑战
   */
  isJon() {
    if (this.pageData[0].UserId == this.api.getUserinfo("UserId")) {
      return false;
    } else {
      if (this.pageData[0].State == 10) {
        return true;
      }
    }
    return false;
  }
  openPersondetial() {



  }
  /**
   * 
   */
  openSelect() {
  }
  ishuanggun(item) {
    let isok = false;
    if (item.State == 30) {
      if (item.Judge == 1) {
        isok = true;
      }
    }
    return isok;
  }


  showMoreActionFlag = false;
  /**
   * 打开分享
   */
  showMoreActionModal() {
    this.showMoreActionFlag = true
  }
  /**
   * 取消分享
   */
  hideMoreActionModal() {
    this.showMoreActionFlag = false
  }
}
